package com.jxust.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

//@WebFilter(urlPatterns =  "/*")//拦截所有请求
@Slf4j
public class DemoFilter implements Filter {

    //初始化方法web服务器启动时执行，只执行一次
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("init 初始化方法.....");
    }

    //拦截到请求后，执行，会执行多次
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info( "拦截到请求.....");
        filterChain.doFilter(servletRequest,servletResponse);//唯一一个放行的
    }


    // 销毁方法，web服务器停止时执行，只执行一次
    @Override
    public void destroy() {
        log.info( "destroy 销毁方法.....");
    }
}
